package rickyGame.game.action
{
	import flash.geom.Point;
	
	import ricky.events.AnimEvent;
	import ricky.game.Actor;
	import ricky.game.action.Act2D;
	import ricky.game.graphic.Graphic;
	
	import rickyGame.game.Fighter;
	import rickyGame.game.GameState;
	import rickyGame.game.SkillObject;
	import rickyGame.game.action.ActionHelper;
	import rickyGame.game.skill.SkillData;
	
	/**
	 * 释放magic技能行动
	 */
	public class SpellAct extends Act2D
	{
		/**
		 * actor:Pu 技能释放者</br>
		 * skill:SkillData 技能数据</br>
		 * target:Pu 攻击目标</br>
		 * point:Point=null 攻击点 </br>
		 */
		public function SpellAct(actor:Actor,skill:SkillData,target:Actor,point:Point=null)
		{
			super(actor);
			_skill=skill;
			this._point=point;
			this._target=target;//攻击目标
		}
		
		
		override public function begin():void
		{
			_state=1;
			var x:Number=actor.graphic.x;
			var y:Number=actor..graphic.y;
			if(_point)
			{
				x=_point.x;
				y=_point.y+5;
			}
			if(_target)
			{
				x=_target.graphic.x;
				y=_target.graphic.y+5;
			}

			_skillObj=new SkillObject(Fighter(actor),_skill);
			_skillObj.graphic.x=x;
			_skillObj.graphic.x=y;
			_skillObj.graphic.wear(_skill.model);
			Graphic(_skillObj.graphic).fps=7;
			
			var ani:AnimaAct;
			var anipro:Array=_skill.animProps;
			var ani1:Act2D;

			
			if(_skill.continueTime<=0)//如果持续时间为0
			{			
				for each(var anis:String in anipro)
				{
					ani=new AnimaAct(_skillObj,anis);
					if(ani1==null)
						ani1=ani;
					else
						ani1.addNext(ani);
				}
				ani1.addEffectNext(effectNext);
				_skillObj.addAct(ani1);

			}
			else
			{
				var end:Number=new Date().getTime()+_skill.continueTime;
				ani=new AnimaAct(_skillObj,anipro[0]);//跑步
				ani.addNext(new TimeAnimAct(_skillObj,anipro[1],end));
				ani.addNext(this.next);
				ani.addEffectNext(this.effectNext);
				_skillObj.addAct(ani);
			}
			
			GameState.inst.sceneManager.addGameObject(_skillObj);

			this.complete();
		}
		
//		override public function end():void
//		{
//			super.end();
//		}
	
		override public function dispose():void
		{
			super.dispose();
			_skillObj=null;
			_skill=null;
		}

		//
		private var _effectType:Function;
		private var _point:Point;
		private var _target:Actor;
		private var _skill:SkillData;
		private var _skillObj:SkillObject;
	}
}